<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>访客记录</title>
    <link rel="stylesheet" th:href="@{/component/pear/css/pear.css}" />

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!---->
    <!--    jq-->
    <script th:src="@{/assets/js/jquery.min.js}"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>


</head>

<style>
    .ip_input {
        width: 40px;
        height: 20px;
        font: normal 16px 宋体;
        color: #000000;
        border: 0px;
        text-align: center;
        position: relative;
        top: 1px;
    }

    .all_input {
        width: 210px;
        height: 30px;
        font: normal 8px 宋体;
        color: #000000;
        border: 1px solid #000000;
        text-align: center;
    }

    #i1 {
        width: 260px;
        height: 30px;
        float: left;
    }

    #i2 {
        width: 54px;
        height: 33.6px;
        float: left;
    }

    #context {
        width: 190px;
        height: 33.6px;
        float: left;
    }

</style>

<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="layui-this">访客记录</li>
                <li>IP查询</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table style="margin-top: 10px;" id="log-login-table" lay-filter="user-table"></table>
                </div>
                <div class="layui-tab-item" id="ipsc">
                    <span>请输入IP：</span>
                    <br/>
<!--                    ip查询-->
                    <form id="cform" class="form-inline" method="post" href="#">
                        <!--                                            <div class="form-group">-->
                        <!--                                                <input type="text" class="form-control" name="categoryName"-->
                        <!--                                                       placeholder="请输入ip">-->
                        <!--                                            </div>-->
                        <div id="i1" class=all_input>
                            <input id="s1" name=ip1 class=ip_input maxlength=3
                                   onkeydown=keyDownEvent(this)
                                   onkeyup=keyUpEvent(ip1,ip1,ip2)><span
                                style="font-size: 16px">.</span>
                            <input id="s2" name=ip2 class=ip_input maxlength=3
                                   onkeydown=keyDownEvent(this)
                                   onkeyup=keyUpEvent(ip1,ip2,ip3)><span
                                style="font-size: 16px">.</span>
                            <input id="s3" name=ip3 class=ip_input maxlength=3
                                   onkeydown=keyDownEvent(this)
                                   onkeyup=keyUpEvent(ip2,ip3,ip4)><span
                                style="font-size: 16px">.</span>
                            <input id="s4" name=ip4 class=ip_input maxlength=3
                                   onkeydown=keyDownEvent(this)
                                   onkeyup=keyUpEventForIp4(ip3,ip4)>
                        </div>
                        <div id="i2">
                            <button type="button" onclick="f()"
                                    class="btn btn-success waves-effect waves-light m-l-10">
                                查询
                            </button>
                        </div>
                        <div id="context" style="width: 200px;height: 50px;margin-left: 20px;"></div>
                    </form>



                </div>
            </div>

        </div>
    </div>
</div>
</body>


<script type="text/html" id="log-createTime">
    {{layui.util.toDateString(d.visit_time,  "yyyy-MM-dd HH:mm:ss")}}
</script>
<script th:src="@{/assets/js/jquery.min.js}"></script>
<script th:src="@{/component/layui/layui.js}"></script>
<script th:src="@{/component/pear/pear.js}"></script>
<script>

    function f() {
        $.ajax({
            url: "/visitor/searchIpaddress",
            data: {
                "ip1": $("#s1").val(),
                "ip2": $("#s2").val(),
                "ip3": $("#s3").val(),
                "ip4": $("#s4").val()
            },
            success: function (data) {
                var json = JSON.parse(data);
                if (json.result == 200) {
                    $("#context").html("<span style='color: #01AAED'>" + json.data + "</span>")
                } else {
                    $("#context").html("<span style='color: #01AAED'>查询异常</span>")
                }

            }

        })

    }

    function getPos(obj) {
        obj.focus();
        var workRange = document.selection.createRange();
        obj.select();
        var allRange = document.selection.createRange();
        workRange.setEndPoint("StartToStart", allRange);
        var len = workRange.text.length;
        workRange.collapse(false);
        workRange.select();
        return len;
    }


    function setCursor(obj, num) {
        range = obj.createTextRange();
        range.collapse(true);
        range.moveStart('character', num);
        range.select();
    }

    function keyDownEvent(obj) {
        code = event.keyCode;
        if (!((code >= 48 && code <= 57) || (code >= 96 && code <= 105) || code == 190 || code == 110 || code == 13 || code == 9 || code == 39 || code == 8 || code == 46 || code == 99 || code == 37))
            event.returnValue = false;
        if (code == 13)
            event.keyCode = 9;
        if (code == 110 || code == 190)
            if (obj.value)
                event.keyCode = 9;
            else
                event.returnValue = false;
    }

    function keyUpEvent(obj0, obj1, obj2) {
        if (obj1.value > 255) {
            alert("填写范围必须在 0 - 255间");
            obj1.value = obj1.value.substring(0, obj1.value.length - 1);
            return;
        }
        code = event.keyCode

        if (obj1.value.length >= 3 && code != 37 && code != 39 && code != 16 && code != 9 && code != 13)
            obj2.focus();

        if (code == 32)
            obj2.focus();

        if (code == 8 && obj1.value.length == 0) {
            obj0.focus();
            setCursor(obj0, obj0.value.length);
        }

        if (code == 37 && (getPos(obj1) == 0)) {
            obj0.focus();
            setCursor(obj0, obj0.value.length);
        }
        if (code == 39 && (getPos(obj1) == obj1.value.length)) {
            obj2.focus();
        }
    }

    function keyUpEventForIp4(obj0, obj) {
        if (obj.value > 255) {
            alert("填写范围必须在 0 - 255间");
            obj.value = obj.value.substring(0, obj.value.length - 1);
            return;
        }
        if (code == 8 && obj.value.length == 0) {
            obj0.focus();
            setCursor(obj0, obj0.value.length);
        }
        if (code == 37 && (getPos(obj) == 0)) {
            obj0.focus();
            setCursor(obj0, obj0.value.length);
        }

    }

    function getipvalue(obj1, obj2, obj3, obj4, obj) {
        obj.value = obj1.value + "." + obj2.value + "." + obj3.value + "." + obj4.value;
        alert(obj.value);
    }




    layui.use(['table','form','jquery','element'],function () {
        let table = layui.table;
        let form = layui.form;
        let element = layui.element;

        let MODULE_PATH = "/system/logging/";

        let cols = [
            [
                {title: 'id', field: 'id', align:'center'},
                {title: 'IP地址', field: 'visit_ip', align:'center'},
                {title: '所在地', field: 'visit_address', align:'center'},
                {title: '浏览器', field: 'browser', align:'center'},
                {title: '操作系统', field: 'os',align:'center'},
                {title: '访问时间', field: 'visit_time',templet:'#log-createTime', align:'center'},
                {title: '描述', field: 'visit_describe', align:'center'}
            ]
        ]

        let cols2 =[





        ]

        // table.render({
        //     elem: '#log-operate-table',
        //     url: '#',
        //     page: true ,
        //     cols: cols ,
        //     skin: 'line',
        //     toolbar: false
        // });

        table.render({
            elem: '#log-login-table',
            url: '/pear/visitorData',
            page: true ,
            cols: cols ,
            skin: 'line',
            toolbar: false
        });

        form.on('submit(dict-type-query)', function(data){
            table.reload('dict-type-table',{where:data.field})
            return false;
        });



        window.error = function(obj){
            layer.open({
                type: 1,
                title: '异常信息',
                shade: 0,
                area: ['450px', '350px'],
                content: '<div class="pear-container"><div class="layui-card"><div class="layui-card-body">'+obj.data['error']+'</div></div></div>'
            });
        }

        $('#ipsc').css('height','500px');


    })
</script>
</html>